package com.java1412.quartz;

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author java1412
 * @create 2021-07-20 15:42
 */
@Configuration
public class QuartzConfig {
    @Bean
    public JobDetail testQuartzDetail() {
        return JobBuilder.newJob(TaskQuartz.class)
                .withIdentity("taskQuartz")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger testQuartzTrigger() {
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                // 设置时间周期，单位秒
                .withIntervalInSeconds(10)
                .repeatForever();
        return TriggerBuilder.newTrigger().forJob(testQuartzDetail())
                .withIdentity("testQuartz")
                .withSchedule(scheduleBuilder)
                .build();
    }
}
